package com.boot23.controller;

import com.boot23.entity.User;
import com.boot23.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author wxd
 * @version 1.0
 */
@Controller
public class UserController {
    @Autowired
    UserMapper mapper;

    @RequestMapping("/reg")
    @ResponseBody
    public String reg(User user) {
        System.out.println("user = " + user);
        mapper.insert(user);
        return user.toString();
    }

    @RequestMapping("/deleteUser")
    @ResponseBody
    public String deleteUser(String name) {
        mapper.deleteByName(name);
        return "删除成功!";
    }

    @RequestMapping("/updateUser")
    @ResponseBody
    public String updateUser(User user) {
        mapper.updateByID(user);
        return "修改成功!";
    }

    @RequestMapping("/queryUser")
    @ResponseBody
    public String queryUser(User user) {
        List<User> list =  mapper.queryUser();
        return list.toString();
    }
}
